package com.it.service;

import com.it.mapper.SysImageMapper;
import com.it.pojo.SysImage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class SysImageServiceImpl implements SysImageService {

	//由spring创建对象并为变量赋值
	@Autowired
	private SysImageMapper sysImageMapper;

	/**
	 * 1.查询所有图片信息
	 * @return
	 */
	public List<SysImage> findAll(){
		//1.调用imageMapper的findAll方法查询所有图片
		List<SysImage> list = sysImageMapper.findAll();
		return list;
	}
	
	/**
	 * 2.根据id删除图片信息
	 * @param id
	 */
	public int deleteById(String id){
		//1.调用ImageMapper的deleteById方法
		//根据id删除图片信息
		int result = sysImageMapper.deleteById(id);
		return result;
	}
	
	/**
	 * 3.添加图片信息
	 * @param image
	 */
	public int addSysImage(SysImage image){
		int result = sysImageMapper.addSysImage(image);
		return result;
	}
	
	/**
	 * 4.1.根据id查询图片信息
	 * @param id
	 * @return 
	 */
	public SysImage findById(String id){
		SysImage image = sysImageMapper.findById(id);
		return image;
	}

	/**
	 * 4.2.根据linkId和linkType查询图片信息
	 * @param linkId
	 * @param linkType
	 * @return
	 */
	public List<SysImage> findByLink(String linkId, int linkType){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("linkId", linkId);
		map.put("linkType", linkType);
		List<SysImage> images = sysImageMapper.findByLink(map);
		return images;
	}
	
	/**
	 * 5.根据id修改图片信息
	 * @param image
	 */
	public int updateById(SysImage image){
		int result = sysImageMapper.updateById(image);
		return result;
	}
	
}
